<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<jsp:include page="../../header.jsp" />
<div class="content-header">
    <h2 class="content-title">部门结构图</h2>
    <div class="action-buttons">
        <a href="department" class="btn btn-back">
            <i class="icon-back"></i> 返回列表
        </a>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <div class="department-tree">
            <h3>公司组织结构</h3>
            <ul class="tree">
                <c:forEach var="dept" items="${departments}">
                    <c:if test="${dept.parentId == 0}">
                        <li>
                            <div class="tree-node">
                                <span class="node-label">${dept.name}</span>
                                <span class="node-info">${dept.employeeCount} 名员工</span>
                            </div>
                            <c:set var="children" value="${departmentDAO.getSubDepartments(dept.id)}" />
                            <c:if test="${not empty children}">
                                <ul>
                                    <c:forEach var="child" items="${children}">
                                        <li>
                                            <div class="tree-node">
                                                <span class="node-label">${child.name}</span>
                                                <span class="node-info">${child.employeeCount} 名员工</span>
                                            </div>
                                            <c:set var="grandChildren" value="${departmentDAO.getSubDepartments(child.id)}" />
                                            <c:if test="${not empty grandChildren}">
                                                <ul>
                                                    <c:forEach var="grandChild" items="${grandChildren}">
                                                        <li>
                                                            <div class="tree-node">
                                                                <span class="node-label">${grandChild.name}</span>
                                                                <span class="node-info">${grandChild.employeeCount} 名员工</span>
                                                            </div>
                                                        </li>
                                                    </c:forEach>
                                                </ul>
                                            </c:if>
                                        </li>
                                    </c:forEach>
                                </ul>
                            </c:if>
                        </li>
                    </c:if>
                </c:forEach>
            </ul>
        </div>
    </div>
</div>
<jsp:include page="../../footer.jsp" />